<template>
  <div class="container">
    <div class="login">
      <span id="span">百杉管理系统</span>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item label="账号" prop="userName">
          <el-input v-model.number="ruleForm.userName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="passWord">
          <el-input v-model.number="ruleForm.passWord"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          callback();
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    return {
      ruleForm: {
        passWord: "",
        userName: "",
      },
      rules: {
        passWord: [{ validator: validatePass, trigger: "blur" }],
        userName: [{ validator: checkAge, trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert("ok");
          console.log("创建成功", this.ruleForm.pass, this.ruleForm.userName);
          this.$axios
            .post("http://wish.byesame.com/login", this.ruleForm)
            .then((res) => {
              console.log(res);
              if (res.data.code == 200) {
                this.$message({
                  message: "登录成功",
                  type: "success",
                });
                localStorage.setItem("token", res.data.data.token); //保存token令牌
                this.$router.replace("/home"); //跳转路由
              } else {
                this.$message.error(res.data.msg); //使用后端返回提示语句
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.login {
  width: 350px;
  height: 450px;
  padding: 0 20px;
  padding-top: 50px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(53, 59, 63, 0.555);
  border-radius: 20px;
  transition: all 1s;
}
.login:hover {
  box-shadow: 0 0 20px 0 rgba(128, 135, 143, 0.512);
}
.el-form {
  width: 100%;
  height: 100%;
}
.el-input {
  width: 90%;
}
#span {
  margin-left: 30%;
  color: white;
  font-size: 20px;
}
>>> .el-form-item__label {
  color: white;
}
.el-form-item {
  height: 100px;
}
>>> .el-input__inner {
  border-radius: 20px;
}
.el-button {
  border-radius: 10px;
}
>>> .el-form-item__content {
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.container {
  width: 100%;
  height: 100%;
  --s: 200px; /* control the size */
  --c1: #1d1d1d;
  --c2: #4e4f51;
  --c3: #3c3c3c;

  background: repeating-conic-gradient(
        from 30deg,
        #0000 0 120deg,
        var(--c3) 0 180deg
      )
      calc(0.5 * var(--s)) calc(0.5 * var(--s) * 0.577),
    repeating-conic-gradient(
      from 30deg,
      var(--c1) 0 60deg,
      var(--c2) 0 120deg,
      var(--c3) 0 180deg
    );
  background-size: var(--s) calc(var(--s) * 0.577);
}
</style>